package com.dwx.gmall.product.controller;


import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dwx.gmall.common.result.Result;
import com.dwx.gmall.model.product.BaseTrademark;
import com.dwx.gmall.product.service.BaseTrademarkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "品牌管理")
@RestController
@RequestMapping("/admin/product")
public class BaseTrademarkController {
    @Autowired
    BaseTrademarkService baseTrademarkService;

    @ApiOperation(value = "分页查询品牌")
    @GetMapping("/baseTrademark/{page}/{limit}")
    public Result<Page<BaseTrademark>> baseTrademarkPage(
            @ApiParam(value = "当前页",required = true)
            @PathVariable("page") Long page,
            @ApiParam(value = "每页显示数",required = true)
            @PathVariable("limit") Long limit
    ){
        Page<BaseTrademark> baseTrademarkPage=new Page<>(page,limit);
        baseTrademarkService.page(baseTrademarkPage);
        return Result.ok(baseTrademarkPage);
    }

    @ApiOperation(value = "保存品牌")
    @PostMapping("/baseTrademark/save")
    public Result<BaseTrademark> saveBaseTrademark(
            @ApiParam(value = "品牌对象",required = true)
            @RequestBody BaseTrademark baseTrademark
    ){
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }

    @ApiOperation(value = "修改品牌")
    @PutMapping("/baseTrademark/update")
    public Result<BaseTrademark> updateBaseTrademark(
            @ApiParam(value = "品牌对象",required = true)
            @RequestBody BaseTrademark baseTrademark
    ){
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }

    @ApiOperation(value = "删除品牌")
    @DeleteMapping("/baseTrademark/remove/{id}")
    public Result<BaseTrademark> removeBaseTrademark(
            @ApiParam(value = "品牌ID",required = true)
            @PathVariable("id") Long id
    ){
        baseTrademarkService.removeById(id);
        return Result.ok();
    }

    @ApiOperation(value = "根据Id查询品牌")
    @GetMapping("/baseTrademark/get/{id}")
    public Result<BaseTrademark> getBaseTrademarkById(
            @ApiParam(value = "品牌ID",required = true)
            @PathVariable("id") Long id
    ){
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }
    @ApiOperation(value = "查詢全部")
    @GetMapping("/baseTrademark/getTrademarkList")
    public Result<List<BaseTrademark>> getTrademarkList(){
        List<BaseTrademark> list = baseTrademarkService.list();
        return Result.ok(list);
    }
}
